<?php
class FlowerOrderVo extends SzAbstractMySqlVo
{

    private $userId;
    private $indexId;
    private $target;
    private $reward;
    private $refreshTime;
    private $status;
    private $refreshTimes;
    private $updateTime;

    /**
     * Initialize FlowerOrderVo.
     *
     * @param $userId
     * @param $indexId
     * @param $target
     * @param $reward
     * @param $refreshTime
     * @param $status
     * @param $refreshTimes
     * @param $updateTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return FlowerOrderVo
     */
    public function __construct($userId, $indexId, $target, $reward, $refreshTime, $status, $refreshTimes, $updateTime, $isInsert = false) {
        $this->userId = $userId;
        $this->indexId = $indexId;
        $this->target = json_decode($target, true);
        $this->reward = json_decode($reward, true);
        $this->refreshTime = $refreshTime;
        $this->status = $status;
        $this->refreshTimes = $refreshTimes;
        $this->updateTime = $updateTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'FlowerOrderVo';
        $this->ormName = 'FlowerOrder';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'target' => ($needEncode) ? $this->getTarget() : $this->getRawTarget(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'refreshTime' => $this->getRefreshTime(),
            'status' => $this->getStatus(),
            'refreshTimes' => $this->getRefreshTimes(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'indexId' => $this->getIndexId(),
            'target' => ($needEncode) ? $this->getTarget() : $this->getRawTarget(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'refreshTime' => $this->getRefreshTime(),
            'status' => $this->getStatus(),
            'refreshTimes' => $this->getRefreshTimes(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getIndexId(),
            $this->getTarget(),
            $this->getReward(),
            $this->getRefreshTime(),
            $this->getStatus(),
            $this->getRefreshTimes(),
            $this->getUpdateTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getIndexId()
    {
        return $this->indexId;
    }

    public function setIndexId($val)
    {
        $this->saveColumnStatus(1, $this->indexId);
        $this->indexId = $val;
    }

    public function getTarget()
    {
        return json_encode($this->target);
    }

    public function getRawTarget()
    {
        return $this->target;
    }

    public function setTarget($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[FlowerOrderVo] The length of column target exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('FlowerOrderVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[FlowerOrderVo] The length of column target exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(2, $this->target);
        $this->target = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[FlowerOrderVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('FlowerOrderVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[FlowerOrderVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(3, $this->reward);
        $this->reward = $val;
    }

    public function getRefreshTime()
    {
        return $this->refreshTime;
    }

    public function setRefreshTime($val)
    {
        $this->saveColumnStatus(4, $this->refreshTime);
        $this->refreshTime = $val;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($val)
    {
        $this->saveColumnStatus(5, $this->status);
        $this->status = $val;
    }

    public function getRefreshTimes()
    {
        return $this->refreshTimes;
    }

    public function setRefreshTimes($val)
    {
        $this->saveColumnStatus(6, $this->refreshTimes);
        $this->refreshTimes = $val;
    }

    public function getUpdateTime()
    {
        return $this->updateTime;
    }

    public function setUpdateTime($val)
    {
        $this->saveColumnStatus(7, $this->updateTime);
        $this->updateTime = $val;
    }

}